package org.example.controller;

import io.swagger.annotations.Api;
import org.springframework.http.HttpRequest;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;

/**
 * @Auther: GongXl
 * @Date: 2021/3/8 23:36
 * @Description:
 */
@Controller
@RequestMapping("/users")
public class UserController {

    /**
     * @Author GongXl
     * @Description auth2测试资源
     * @Date 2021/3/13 19:46
     * @Param [auth]
     * @return java.lang.Object
     **/
    @RequestMapping("/getCurUser")
    @ResponseBody
    public Object getCurUser(Authentication auth){
        return auth.getPrincipal();
    }

    @RequestMapping("/login2")
    @ResponseBody
    public Map login(){
        System.out.println("login...");
        return null;
    }
    @RequestMapping("/logout")
    @ResponseBody
    public Map logout(){
        System.out.println("logout...");
        return null;
    }
    @RequestMapping("/login_page")
    public String login_page(){
        System.out.println("login_page...");
        return "test.html";
    }
    /**
     * @Author GongXl
     * @Description 登录前触发生成验证码
     * @Date 2021/3/24 11:11
     * @Param [request]
     * @return java.util.Map
     **/
    @RequestMapping("/captcha")
    @ResponseBody
    public Map captcha(HttpServletRequest request){
        System.out.println("captcha...");
        request.getSession().setAttribute("codeValue","11111");
        System.out.println("验证码的session:"+request.getSession().getId());
        request.getSession().setAttribute("codeTime",(new Date()).getTime());
        return null;
    }
}